package com.kingyun.gpsinspection.purificationservice.services.iam.innerservice.accessory.impl;

import com.kingyun.gpsinspection.purificationservice.facade.service.iam.accessory.IamEmployeeVoService;
import com.kingyun.gpsinspection.purificationservice.facade.model.jsm.Employee;
import com.kingyun.gpsinspection.purificationservice.facade.model.jsm.Ztree;
import com.kingyun.gpsinspection.purificationservice.facade.service.jsm.OutEmployeeService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ${yangsy} on 2017/3/25.
 */
public class IamEmployeeVoServiceImpl implements IamEmployeeVoService
{
    private static org.slf4j.Logger logger = LoggerFactory.getLogger(IamEmployeeVoServiceImpl.class);
    @Autowired(required = false)
    private OutEmployeeService outEmployeeService;


    @Override
    public List<Ztree> listStaff(String orgId, String iconSkin, String search, Employee employee) {
        List<Ztree> list = new ArrayList<>();
        if (StringUtils.isBlank(orgId) || orgId.equals("undefined")) orgId = employee.getOrgId();
        try {
            if(StringUtils.isEmpty(search)){
                if (StringUtils.isEmpty(iconSkin)) {
                    //初始化
                    list.addAll(outEmployeeService.loadEmployeeZtree(orgId, true , false, false, search));
                } else {
                    //点击+号：展开异步
                    //展开组织
                    if(!iconSkin.equals("department")){
                        list.addAll(outEmployeeService.loadEmployeeZtree(orgId, false, true, false, search));
                        //展开部门
                    }else{
                        list.addAll(outEmployeeService.loadEmployeeZtree(orgId, false, false, true, search));
                    }
                }
            }else{
                if (StringUtils.isEmpty(iconSkin)) {
                    //初始化
                    list.addAll(outEmployeeService.loadEmployeeZtree(orgId, true, false, false, search));
                } else {
                    //点击+号：展开异步
                    //展开组织
                    if(!iconSkin.equals("department")){
                        list.addAll(outEmployeeService.loadEmployeeZtree(orgId, false, true, false, search));
                        //展开部门
                    }else{
                        list.addAll(outEmployeeService.loadEmployeeZtree(orgId, false, false, true, search));
                    }
                }
            }

            System.out.println("数量：" + list.size());
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return list;
    }

}
